//
//  wsPgapAppDelegate.m
//  wsPgap
//
//  Created by Oleksandr Kulinchenko on 27/04/2011.
//  Copyright __MyCompanyName__ 2011. All rights reserved.
//

#import "wsPgapAppDelegate.h"
#import "PhoneGapViewController.h"

@implementation wsPgapAppDelegate

- (id) init
{	
	/** If you need to do any extra app-specific initialization, you can do it here
	 *  -jm
	 **/
    return [super init];
}

/**
 * This is main kick off after the app inits, the views and Settings are setup here.
 */
- (void)applicationDidFinishLaunching:(UIApplication *)application
{	
	[ super applicationDidFinishLaunching:application ];
	
}

-(id) getCommandInstance:(NSString*)className
{
	/** You can catch your own commands here, if you wanted to extend the gap: protocol, or add your
	 *  own app specific protocol to it. -jm
	 **/
	return [super getCommandInstance:className];
}

/**
 Called when the webview finishes loading.  This stops the activity view and closes the imageview
 */
- (void)webViewDidFinishLoad:(UIWebView *)theWebView 
{
	return [ super webViewDidFinishLoad:theWebView ];
}

- (void)webViewDidStartLoad:(UIWebView *)theWebView 
{
	return [ super webViewDidStartLoad:theWebView ];
}

/**
 * Fail Loading With Error
 * Error - If the webpage failed to load display an error with the reson.
 */
- (void)webView:(UIWebView *)theWebView didFailLoadWithError:(NSError *)error 
{
	
	return [ super webView:theWebView didFailLoadWithError:error ];
}




- (BOOL) execute:(InvokedUrlCommand*)command
{
	return [ super execute:command];
}

- (void)dealloc
{
	[ super dealloc ];
}


+ (NSString*) startPage;
{
	return @"index.html";
}

/** 
 * Start Loading Request 
 * This is where most of the magic happens... We take the request(s) and 
 process the response. 
 * From here we can re direct links and other protocalls to different 
 internal methods. 
 */ 
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{ 
	NSURL *url = [request URL]; 
	// add any other schemes you want to support, or perform additional 
	// tests on the url before deciding what to do -jm 
	if( [[url scheme] isEqualToString:@"http"] || 
	   [[url scheme] isEqualToString:@"https"]) 
	{ 
		[[UIApplication sharedApplication] openURL:url]; 
		return NO; 
	} 
	
	else 
	{ 
		return [ super webView:theWebView shouldStartLoadWithRequest:request 
				navigationType:navigationType ]; 
	} 
} 

@end
